class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        unordered_map<string,int> hash1;//保存words里面的所有单词的频次
        for(auto& s:words) hash1[s]++;
        vector<int> ret;
        int len=words[0].size(),m=words.size();
        for(int i=0;i<len;i++)//执行len次滑动窗口的操作
        {   
            unordered_map<string,int> hash2;
            for(int left=i,right=i,count=0;right+len<=s.size();right+=len)
            {
                string in=s.substr(right,len);
                hash2[in]++;
                if(hash2[in]<=hash1[in])
                    count++;
                if((right-left)/len+1>m)
                {
                    string out=s.substr(left,len);
                    left+=len;
                    if(hash2[out]<=hash1[out])
                        count--;
                    hash2[out]--;
                }
                if(count==m)
                    ret.push_back(left);
            }
        }
        return  ret;
    }
};
